﻿using System;
using System.Collections.Generic;
using System.Xml;
using Navigant.Infrastructure.Cases;
using Navigant.Infrastructure.ClientPortals;
using Navigant.Infrastructure.RepositoryFramework;

namespace Navigant.Model.ClientPortals
{
    public static class ClientPortalService
    {
        private static IClientPortalRepository repository;

        static ClientPortalService()
        {
            ClientPortalService.repository = ClientPortalRepositoryFactory.GetClientPortalRepository();
        }

        public static ClientPortal GetClientPortalBy(Uri caseAddress)
        {
            ClientPortal portalItem = null;
            IClientPortal foundPortal = ClientPortalService.repository.FindBy(caseAddress);
            if (foundPortal != null)
            {
                portalItem = new ClientPortal(foundPortal);
            }
            return portalItem;
        }

        public static ClientPortal GetClientPortalBy(Guid siteCollectionKey)
        {
            ClientPortal portalItem = null;
            IClientPortal foundPortal = ClientPortalService.repository.FindBy(siteCollectionKey);
            if (foundPortal != null)
            {
                portalItem = new ClientPortal(foundPortal);
            }
            return portalItem;
        }

        public static IList<ICase> FindAllCases(Guid siteCollectionKey)
        {
            return ClientPortalService.repository.FindAllCases(siteCollectionKey);
        }

        public static IList<ICase> FindAllCases(Guid siteCollectionKey, string siteDirectoryName,
            string categoryName, string categoryValue)
        {
            return ClientPortalService.repository.FindAllCases(siteCollectionKey, siteDirectoryName,
                categoryName, categoryValue);
        }

        public static IList<string> GetCaseSiteCategories(Guid clientPortalId,
            string siteDirectoryName, string categoryName)
        {
            return ClientPortalService.repository.GetCaseSiteCategories(clientPortalId, 
                siteDirectoryName, categoryName);
        }

        public static string GetDefaultCaseSiteCategory(Guid clientPortalId,
            string siteDirectoryName, string categoryName)
        {
            return ClientPortalService.repository.GetDefaultCaseSiteCategory(clientPortalId, 
                siteDirectoryName, categoryName);
        }

        public static void SaveXmlFileToDocumentLibrary(IClientPortal clientPortal,
            XmlDocument document, string documentLibraryName, string fileName)
        {
            ClientPortalService.repository.SaveXmlFileToDocumentLibrary(clientPortal, 
                document, documentLibraryName, fileName);
        }
    }
}
